package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 分页查询订单列表
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单id查询订单
     * @param orderId
     * @return
     */
    @Select("select * from orders where id = #{orderId}")
    Orders selectById(Long orderId);

    /**
     * 查询各类状态下的订单数量
     * @param status
     * @return
     */
    @Select("select count(0) from orders where status = #{status}")
    Integer countByStatus(Integer status);

    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByOrderTimeAndStatus(LocalDateTime orderTime, Integer status);

    /**
     * 查询一天的营业额
     * @param beginTime
     * @param endTime
     * @return
     */
    Double getTurnoverByDate(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    /**
     * 查询销量top10
     * @param beginTime
     * @param endTime
     * @return
     */
    List<GoodsSalesDTO> selectTop10(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 根据日期和订单状态查询一天的订单数
     * @param beginTime
     * @param endTime
     * @param status
     * @return
     */
    Integer countByDateAndStatus(LocalDateTime beginTime, LocalDateTime endTime, Integer status);
}
